#coding=utf-8
import redis
import MySQLdb

pool = redis.ConnectionPool(host='118.89.225.98')
r = redis.Redis(connection_pool=pool)
db = MySQLdb.connect("118.89.225.98", "root", "123456", "ehotel", charset='utf8' )

def my_scheduled_job():
    cursor = db.cursor()
    cursor.execute("select id, room_num from operation_hotelorder where type in (1, 2) and e_time < now();")
    data = cursor.fetchall()
    ids = []
    room_nums = []
    for i in data:
        ids.append(int(i[0]))
        room_nums.append(str(i[1]))
    if ids and room_nums:
        sql =  'update operation_hotelorder set type = 3 where id in %s;' % str(tuple(ids))
        cursor.execute(sql)
        sql = 'update room_room set status = 1 where num in %s;' % str(tuple(room_nums))
        cursor.execute(sql)
        db.commit()
        r.lpush('msg_list', *room_nums)

if __name__ == '__main__':
    scheduled_rant_job()